<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>进度条动画</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <div id="test" style="width:1px;height:17px;background:#0f0;">0%</div>
  <input type="button" value="Run" id="run" />
</body>
<script>
  "use strict"; {
    window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
    var ele = document.getElementById("test");
    var progress = 0;
    function step(timestamp) {
      progress += 0.05;
      ele.style.width = progress + "%";
      ele.innerHTML = progress + "%";
      if (progress < 100) {
        requestAnimationFrame(step);
      }
    }
    requestAnimationFrame(step);
    document.getElementById("run").addEventListener("click", function () {
      ele.style.width = "1px";
      progress = 0;
      requestAnimationFrame(step);
    }, false);
  }
</script>

</html>